package com.nio.c2_Path;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @version No one is coming, unless you change yourself!!!
 * @author： pang-yun
 * @date： 2021-05-31 16:28
 */


//copy 有内容的文件夹
public class FileCopy {
    public static void main(String[] args) throws IOException {
        String source="G:\\photo";
        String target ="G:\\target";

        Files.walk(Paths.get(source)).forEach(path -> {
            try {
                String targetName = path.toString().replace(source, target);
                if (Files.isDirectory(path)) {
                    Files.createDirectory(Paths.get(targetName));
                }
                //是普通文件的话
                else if (Files.isRegularFile(Paths.get(String.valueOf(path)))){
                 Files.copy(path,Paths.get(targetName));
                    System.out.println("photo");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }


        });
    }

}
